#include "storageadd.h"
#include "ui_storageadd.h"
#include <QToolButton>
#include <QMessageBox>
StorageAdd::StorageAdd(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::StorageAdd)
{
    ui->setupUi(this);
    showFullScreen();
    ui->foodSelect->setParent(this);
    connect(ui->foodSelect,&FoodSelect::selected,this,[=](Food food){
        this->selected = food;
        this->haveSelected = true;
        ui->label_name->setText("食物:"+food.name);
    });
    connect(ui->btn_back,&QToolButton::clicked,[=](){
        this->close();
        //    ui->stackedWidget->setCurrentIndex(ui->stackedWidget->currentIndex()+1);
    });
    connect(ui->btn_complete,&QToolButton::clicked,[=](){
        if (haveSelected&&(ui->amount->text()!=NULL&&ui->amount->text()!="")){
            int amount = ui->amount->text().toInt();
            if (amount<=0){
                QMessageBox::critical(this, tr("存储添加错误"), tr("请输入正确的数量，且保证数量>0"));
            }
            else{
                sql.storageAdd(selected.create_user,selected.create_id,amount);
                qDebug()<<"成功添加";
                emit completed();
                this->close();
            }


        }
        // 添加成功
    });
}

StorageAdd::~StorageAdd()
{
    delete ui;
}
